Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite pam faillock related implementation and template #12654

Merged
merged 2 commits into from
Dec 10, 2024

Conversation

alanmcanonical
Copy link
Contributor

@alanmcanonical alanmcanonical commented Nov 29, 2024

Description:

  • Rewrite pam faillock related implementation and template
  • Use pam-auth-update to implement dynamic pam stack modification
  • Clean up duplicated accounts_passwords_pam_faillock_deny tests
  • Remove general template tests

Rationale:

  • Use clean pam-auth-update configuration to override the /etc/pam.d/common-* configuration instead of modifying PAM files directly
  • There is no way to initialize the {{{ EXT_VARIABLE }}} in tests scripts which later will init to var_accounts_passwords_pam_faillock_{deny, unlock_time, interval} in bash remediation, at least no to my knowledge.

@openshift-ci openshift-ci bot added the needs-ok-to-test Used by openshift-ci bot. label Nov 29, 2024
Copy link

openshift-ci bot commented Nov 29, 2024

Hi @alanmcanonical. Thanks for your PR.

I'm waiting for a ComplianceAsCode member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link

Start a new ephemeral environment with changes proposed in this pull request:

rhel8 (from CTF) Environment (using Fedora as testing environment)
Open in Gitpod

Fedora Testing Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

Copy link

github-actions bot commented Nov 29, 2024

This datastream diff is auto generated by the check Compare DS/Generate Diff

Click here to see the full diff
bash remediation for rule 'xccdf_org.ssgproject.content_rule_account_passwords_pam_faillock_audit' differs.
--- xccdf_org.ssgproject.content_rule_account_passwords_pam_faillock_audit
+++ xccdf_org.ssgproject.content_rule_account_passwords_pam_faillock_audit
@@ -27,14 +27,16 @@
 fi
 
 AUTH_FILES=("/etc/pam.d/system-auth" "/etc/pam.d/password-auth")
+SKIP_FAILLOCK_CHECK=false
 
 FAILLOCK_CONF="/etc/security/faillock.conf"
-if [ -f $FAILLOCK_CONF ]; then
+if [ -f $FAILLOCK_CONF ] || [ "$SKIP_FAILLOCK_CHECK" = "true" ]; then
     regex="^\s*audit"
     line="audit"
     if ! grep -q $regex $FAILLOCK_CONF; then
         echo $line >> $FAILLOCK_CONF
     fi
+    
     for pam_file in "${AUTH_FILES[@]}"
     do
         if [ -e "$pam_file" ] ; then
@@ -82,6 +84,7 @@
             echo "$pam_file was not found" >&2
         fi
     done
+    
 else
     for pam_file in "${AUTH_FILES[@]}"
     do

bash remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_audit' differs.
--- xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_audit
+++ xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_audit
@@ -29,14 +29,16 @@
 fi
 
 AUTH_FILES=("/etc/pam.d/system-auth" "/etc/pam.d/password-auth")
+SKIP_FAILLOCK_CHECK=false
 
 FAILLOCK_CONF="/etc/security/faillock.conf"
-if [ -f $FAILLOCK_CONF ]; then
+if [ -f $FAILLOCK_CONF ] || [ "$SKIP_FAILLOCK_CHECK" = "true" ]; then
     regex="^\s*audit"
     line="audit"
     if ! grep -q $regex $FAILLOCK_CONF; then
         echo $line >> $FAILLOCK_CONF
     fi
+    
     for pam_file in "${AUTH_FILES[@]}"
     do
         if [ -e "$pam_file" ] ; then
@@ -84,6 +86,7 @@
             echo "$pam_file was not found" >&2
         fi
     done
+    
 else
     for pam_file in "${AUTH_FILES[@]}"
     do

bash remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_deny' differs.
--- xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_deny
+++ xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_deny
@@ -32,9 +32,10 @@
 fi
 
 AUTH_FILES=("/etc/pam.d/system-auth" "/etc/pam.d/password-auth")
+SKIP_FAILLOCK_CHECK=false
 
 FAILLOCK_CONF="/etc/security/faillock.conf"
-if [ -f $FAILLOCK_CONF ]; then
+if [ -f $FAILLOCK_CONF ] || [ "$SKIP_FAILLOCK_CHECK" = "true" ]; then
     regex="^\s*deny\s*="
     line="deny = $var_accounts_passwords_pam_faillock_deny"
     if ! grep -q $regex $FAILLOCK_CONF; then
@@ -42,6 +43,7 @@
     else
         sed -i --follow-symlinks 's|^\s*\(deny\s*=\s*\)\(\S\+\)|\1'"$var_accounts_passwords_pam_faillock_deny"'|g' $FAILLOCK_CONF
     fi
+    
     for pam_file in "${AUTH_FILES[@]}"
     do
         if [ -e "$pam_file" ] ; then
@@ -89,6 +91,7 @@
             echo "$pam_file was not found" >&2
         fi
     done
+    
 else
     for pam_file in "${AUTH_FILES[@]}"
     do

bash remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_deny_root' differs.
--- xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_deny_root
+++ xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_deny_root
@@ -29,14 +29,16 @@
 fi
 
 AUTH_FILES=("/etc/pam.d/system-auth" "/etc/pam.d/password-auth")
+SKIP_FAILLOCK_CHECK=false
 
 FAILLOCK_CONF="/etc/security/faillock.conf"
-if [ -f $FAILLOCK_CONF ]; then
+if [ -f $FAILLOCK_CONF ] || [ "$SKIP_FAILLOCK_CHECK" = "true" ]; then
     regex="^\s*even_deny_root"
     line="even_deny_root"
     if ! grep -q $regex $FAILLOCK_CONF; then
         echo $line >> $FAILLOCK_CONF
     fi
+    
     for pam_file in "${AUTH_FILES[@]}"
     do
         if [ -e "$pam_file" ] ; then
@@ -84,6 +86,7 @@
             echo "$pam_file was not found" >&2
         fi
     done
+    
 else
     for pam_file in "${AUTH_FILES[@]}"
     do

bash remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_dir' differs.
--- xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_dir
+++ xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_dir
@@ -32,9 +32,10 @@
 fi
 
 AUTH_FILES=("/etc/pam.d/system-auth" "/etc/pam.d/password-auth")
+SKIP_FAILLOCK_CHECK=false
 
 FAILLOCK_CONF="/etc/security/faillock.conf"
-if [ -f $FAILLOCK_CONF ]; then
+if [ -f $FAILLOCK_CONF ] || [ "$SKIP_FAILLOCK_CHECK" = "true" ]; then
     regex="^\s*dir\s*="
     line="dir = $var_accounts_passwords_pam_faillock_dir"
     if ! grep -q $regex $FAILLOCK_CONF; then
@@ -42,6 +43,7 @@
     else
         sed -i --follow-symlinks 's|^\s*\(dir\s*=\s*\)\(\S\+\)|\1'"$var_accounts_passwords_pam_faillock_dir"'|g' $FAILLOCK_CONF
     fi
+    
     for pam_file in "${AUTH_FILES[@]}"
     do
         if [ -e "$pam_file" ] ; then
@@ -89,6 +91,7 @@
             echo "$pam_file was not found" >&2
         fi
     done
+    
 else
     for pam_file in "${AUTH_FILES[@]}"
     do

bash remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_enforce_local' differs.
--- xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_enforce_local
+++ xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_enforce_local
@@ -29,14 +29,16 @@
 fi
 
 AUTH_FILES=("/etc/pam.d/system-auth" "/etc/pam.d/password-auth")
+SKIP_FAILLOCK_CHECK=false
 
 FAILLOCK_CONF="/etc/security/faillock.conf"
-if [ -f $FAILLOCK_CONF ]; then
+if [ -f $FAILLOCK_CONF ] || [ "$SKIP_FAILLOCK_CHECK" = "true" ]; then
     regex="^\s*local_users_only"
     line="local_users_only"
     if ! grep -q $regex $FAILLOCK_CONF; then
         echo $line >> $FAILLOCK_CONF
     fi
+    
     for pam_file in "${AUTH_FILES[@]}"
     do
         if [ -e "$pam_file" ] ; then
@@ -84,6 +86,7 @@
             echo "$pam_file was not found" >&2
         fi
     done
+    
 else
     for pam_file in "${AUTH_FILES[@]}"
     do

bash remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_interval' differs.
--- xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_interval
+++ xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_interval
@@ -32,9 +32,10 @@
 fi
 
 AUTH_FILES=("/etc/pam.d/system-auth" "/etc/pam.d/password-auth")
+SKIP_FAILLOCK_CHECK=false
 
 FAILLOCK_CONF="/etc/security/faillock.conf"
-if [ -f $FAILLOCK_CONF ]; then
+if [ -f $FAILLOCK_CONF ] || [ "$SKIP_FAILLOCK_CHECK" = "true" ]; then
     regex="^\s*fail_interval\s*="
     line="fail_interval = $var_accounts_passwords_pam_faillock_fail_interval"
     if ! grep -q $regex $FAILLOCK_CONF; then
@@ -42,6 +43,7 @@
     else
         sed -i --follow-symlinks 's|^\s*\(fail_interval\s*=\s*\)\(\S\+\)|\1'"$var_accounts_passwords_pam_faillock_fail_interval"'|g' $FAILLOCK_CONF
     fi
+    
     for pam_file in "${AUTH_FILES[@]}"
     do
         if [ -e "$pam_file" ] ; then
@@ -89,6 +91,7 @@
             echo "$pam_file was not found" >&2
         fi
     done
+    
 else
     for pam_file in "${AUTH_FILES[@]}"
     do

bash remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_unlock_time' differs.
--- xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_unlock_time
+++ xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_unlock_time
@@ -32,9 +32,10 @@
 fi
 
 AUTH_FILES=("/etc/pam.d/system-auth" "/etc/pam.d/password-auth")
+SKIP_FAILLOCK_CHECK=false
 
 FAILLOCK_CONF="/etc/security/faillock.conf"
-if [ -f $FAILLOCK_CONF ]; then
+if [ -f $FAILLOCK_CONF ] || [ "$SKIP_FAILLOCK_CHECK" = "true" ]; then
     regex="^\s*unlock_time\s*="
     line="unlock_time = $var_accounts_passwords_pam_faillock_unlock_time"
     if ! grep -q $regex $FAILLOCK_CONF; then
@@ -42,6 +43,7 @@
     else
         sed -i --follow-symlinks 's|^\s*\(unlock_time\s*=\s*\)\(\S\+\)|\1'"$var_accounts_passwords_pam_faillock_unlock_time"'|g' $FAILLOCK_CONF
     fi
+    
     for pam_file in "${AUTH_FILES[@]}"
     do
         if [ -e "$pam_file" ] ; then
@@ -89,6 +91,7 @@
             echo "$pam_file was not found" >&2
         fi
     done
+    
 else
     for pam_file in "${AUTH_FILES[@]}"
     do

Copy link
Contributor

@mpurg mpurg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor changes needed


sed -i '/pam_faillock\.so/d' /etc/pam.d/common-auth
sed -i '/pam_faillock\.so/d' /etc/pam.d/common-account
DEBIAN_FRONTEND=noninteractive pam-auth-update

echo "deny=1" > /etc/security/faillock.conf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter deny should not be hardcoded in the test since it's not used in other rules that use the template:

  • accounts_passwords_pam_faillock_unlock_time
  • accounts_passwords_pam_faillock_interval

Use {{{ PRM_NAME }}}, {{{ VARIABLE_UPPER_BOUND }}}, and {{{ VARIABLE_LOWER_BOUND }}} instead.

@@ -1,6 +1,5 @@
#!/bin/bash
# platform = multi_platform_ubuntu

source ubuntu_common.sh

{{{ bash_enable_pam_faillock_directly_in_pam_files() }}}
echo "deny=999" > /etc/security/faillock.conf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous comment.

.github/workflows/automatus-ubuntu2404.yml Outdated Show resolved Hide resolved
Copy link
Contributor

@dodys dodys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a rebase now that the automatus changes were merged

@dodys dodys added the Update Template Issues or pull requests related to Templates updates. label Dec 2, 2024
@dodys dodys added this to the 0.1.76 milestone Dec 2, 2024
@alanmcanonical alanmcanonical marked this pull request as draft December 2, 2024 11:00
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Used by openshift-ci bot. label Dec 2, 2024
@dodys dodys self-assigned this Dec 2, 2024
@dodys dodys added the Ubuntu Ubuntu product related. label Dec 2, 2024
@alanmcanonical alanmcanonical marked this pull request as ready for review December 2, 2024 16:10
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Used by openshift-ci bot. label Dec 2, 2024
@alanmcanonical alanmcanonical marked this pull request as draft December 2, 2024 18:56
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Used by openshift-ci bot. label Dec 2, 2024
@alanmcanonical alanmcanonical force-pushed the ubuntu_enable_faillock branch 2 times, most recently from 3485720 to e621940 Compare December 6, 2024 14:18
Add correct os into applicable platform
Update the ubuntu oval to pass on both required and requisite
Remove the check for authsucc since preauth can clear the count too
Implement individual tests for pam_faillock_{deny, unlock_time, interval}
Copy link

codeclimate bot commented Dec 6, 2024

Code Climate has analyzed commit cf728c8 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 60.9% (0.0% change).

View more on Code Climate.

@alanmcanonical alanmcanonical marked this pull request as ready for review December 9, 2024 09:49
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Used by openshift-ci bot. label Dec 9, 2024
Copy link
Contributor

@dodys dodys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@dodys dodys merged commit f1d163c into ComplianceAsCode:master Dec 10, 2024
93 of 98 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ok-to-test Used by openshift-ci bot. Ubuntu Ubuntu product related. Update Template Issues or pull requests related to Templates updates.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants